﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using GCELibrary.Current;

namespace ZF.WS.UserControls.Index
{
    public partial class PopularizeCompany : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
            var typeList = DictionaryConfig.APopularizeCompanyType;
            this.lvTitle.DataSource = typeList;
            this.lvTitle.DataBind();
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                List<object> list = null; 
                var cacheKey = "PopularizeCompany";
                var obj = HttpCache.GetCache(cacheKey);
                if (obj != null)
                {
                    list = obj as List<object>;
                }
                else
                {
                     list = dc.AD_Popularize.OrderByDescending(p=>p.OrderId)
                            .Take(10).ToList().Select(p =>
                             (object)new
                             {
                                 Popularize = p,
                                 Url = string.IsNullOrEmpty(p.Url) ? "/ads/Company.aspx?id=" + p.PopularizeId.ToString() : p.Url,
                             }).ToList();
                     SiteInfo.Instance.SetPageCache(cacheKey,list);
                }


                var isRecommendList = dc.SP_Merchandise.Where(p => p.IsRecommend && !p.IsDel)
                      .OrderByDescending(p => p.MerchandiseId)
                      .OrderByDescending(p => p.OrderID)
                      .OrderByDescending(p => p.IsHot)
                      .OrderByDescending(p => p.IsRecommend)
                  .ToList().Select(p => new
                  {
                      Merc = p,
                      Photo = p.FirstPhoto,
                  })
              .Take(12).ToList();
                this.lvList.DataSource = isRecommendList;
                this.lvList.DataBind();

 
            }



        }
    }
}